package com.lzs.baseruku.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzs.baseruku.mapper.ReceiveMapper;
import com.lzs.baseruku.service.ReceiveService;
import com.lzs.entity.Receive;
import com.lzs.entity.User;
import com.lzs.util.R;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ymx
 * @since 2020-11-25
 */
@Service
public class ReceiveServiceImpl extends ServiceImpl<ReceiveMapper, Receive> implements ReceiveService {

    @Autowired
    private ReceiveMapper receiveMapper;

    @Override
    public Page<Receive> selectreceive(Integer page, Integer limit, Receive receive) {
        Page<Receive> pageInfo=new Page<>(page,limit);
        String receiveno=receive.getReceiveno();
        String purchaseno=receive.getPurchaseno();
        String allocationno=receive.getAllocationno();
        String state=receive.getState();
        QueryWrapper queryWrapper=new QueryWrapper();
        if (StringUtils.isNotEmpty(receiveno)){
            queryWrapper.like("receiveno",receiveno);
        }
        if (StringUtils.isNotEmpty(purchaseno)){
            queryWrapper.like("purchaseno",purchaseno);
        }
        if (StringUtils.isNotEmpty(allocationno)){
            queryWrapper.like("allocationno",allocationno);
        }
        if (StringUtils.isNotEmpty(state)){
            queryWrapper.like("state",state);
        }
        this.baseMapper.selectPage(pageInfo,queryWrapper);
        return pageInfo;
    }

    @Override
    public R updateState(List<Long> ids, String state) {
        int i = receiveMapper.updateState(ids, state);
        if (i>0){
            return R.ok().message("操作成功");
        }else {
            return R.error().message("操作失败");
        }
    }

    @Override
    public User selectUserByid(Long userid) {
        return receiveMapper.selectUserById(userid);
    }
}
